
/*
 * Copyright (C) 2008-2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: AbstractSchemaUpdate.java 377 2010-03-11 20:50:18Z archie.cobbs $
 */

package org.dellroad.sidekar.schema.change;

import org.dellroad.sidekar.schema.model.SchemaModel;

/**
 * {@link SchemaChange} that changes an entity's abstractness.
 *
 * <p>
 * If the entity is changing from non-abstract to abstract, there must not exist any exact instances
 * of the entity.
 */
public class EntityAbstractnessChange extends EntityChange {

    private final boolean abstractness;

    /**
     * Constructor.
     *
     * @param entityName name of the entity to alter
     * @param abstractness true to make the entity abstract, or false to make it not abstract
     * @throws IllegalArgumentException if {@code entityName} is not a legal entity name
     */
    public EntityAbstractnessChange(String entityName, boolean abstractness) {
        super(entityName);
        this.abstractness = abstractness;
    }

    public boolean getAbstractness() {
        return this.abstractness;
    }

    @Override
    public String getDescription() {
        return "make entity `" + this.getEntityName() + "' " + (this.abstractness ? "" : "not ") + " abstract";
    }

    @Override
    public void checkValidFor(SchemaModel schemaModel) {
        super.checkValidFor(schemaModel);
        this.checkEntityExists(schemaModel, this.getEntityName());
    }

    @Override
    public final void visit(SchemaChangeSwitch schemaChangeSwitch) {
        schemaChangeSwitch.caseEntityAbstractnessChange(this);
    }
}

